/**
 * 
 * 广州锐鹏计算机科技有限公司（www.ruipengkj.com）
 * 
 * 
 * Copyright (c) 2011-2012 RUIPENGKJ.Co.Ltd. All rights reserved.
 * 
 * */
package com.ruipengkj.model;
/**
 * 商品销售汇总表
 * 黄盛强
 */
import java.util.List;
import java.util.Vector;

import javax.swing.table.AbstractTableModel;

import com.ruipengkj.bean.ViewCommodityOrderSummary;

public class ViewCommoditySalesSummaryModel extends AbstractTableModel {

	private static final long serialVersionUID = 1L;
	private Vector<List<Object>> rowdatas=new Vector<List<Object>>();
	private Vector<String> columns = new Vector<String>();
	public ViewCommoditySalesSummaryModel(){
		columns.add("商品编号");
		columns.add("商品名称");
		columns.add("商品数量");
		columns.add("总金额");
	}
	
	@Override
	public Class<?> getColumnClass(int columnIndex) {
		switch(columnIndex) {
		case 2:
		case 3:
			return Double.class;
		}
		return super.getColumnClass(columnIndex);
	}
	
	//获得行数
	public int getRowCount(){
		return rowdatas.size();
	}
	//获得列数
	public int getColumnCount(){
		return columns.size();
	}
	//获得单元格的值
	public Object getValueAt(int row,int column){
		return ((Vector)rowdatas.get(row)).get(column);
	}
	//获取列名
	public String getColumnName(int column){
		return (String)columns.get(column);
	}
	
	//设置单元格是否可编辑
	public boolean isCellEditable(int rowIndex,int columnIndex){
		return false;
	}
	
	public void removeData(int row){
		rowdatas.remove(row);
	}
	//设置单元格的值
	public void setValueAt(Object aValue,int rowIndex,int columnIndex){
		//取出对应的记录
		Vector rowdata = (Vector)rowdatas.get(rowIndex);
		//删除原来的值
		rowdata.remove(columnIndex);
		//添加用户新修改的值
		rowdata.add(columnIndex,aValue);
	}
	
	public void setRowData(List<ViewCommodityOrderSummary> viewCommodityOrderSummaryList) {
		rowdatas.clear();
		if(viewCommodityOrderSummaryList != null && viewCommodityOrderSummaryList.size() != 0){
			for(int i = 0;i < viewCommodityOrderSummaryList.size();i++){
				ViewCommodityOrderSummary viewCommodityOrderSummary = viewCommodityOrderSummaryList.get(i);
				List<Object> row=new Vector<Object>();
				row.add(viewCommodityOrderSummary.getCommodityID());
				row.add(viewCommodityOrderSummary.getCommodityName());
				row.add(viewCommodityOrderSummary.getTotalNumber());
				row.add(viewCommodityOrderSummary.getTotalPrice());
				rowdatas.add(row);
			}
		}
	}

	public void clear() {
		rowdatas.clear();		
	}
}
